package com.jeff.tianti.controller;

import com.jeff.tianti.cms.dto.font.PrizeFontDTO;
import com.jeff.tianti.cms.entity.AwardRecord;
import com.jeff.tianti.cms.entity.Prize;
import com.jeff.tianti.cms.service.AwardRecordService;
import com.jeff.tianti.cms.service.ColumnInfoService;
import com.jeff.tianti.cms.service.PrizeService;
import com.jeff.tianti.common.dto.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/award")
@CrossOrigin(maxAge = 3600)
public class AwardController {

    @Autowired
    AwardRecordService awardRecordService;

    @Autowired
    PrizeService prizeService;

    /**
     * 获取 友联列表
     *
     * @return
     */
    @RequestMapping(value = "detail", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public AjaxResult index(@RequestBody PrizeFontDTO prizeFontDTO) {

        List<Prize> prizeList = prizeService.findAllByColumnId(prizeFontDTO.getColumnId());
        Prize prize=null;
        if (!CollectionUtils.isEmpty(prizeList)){
             prize = prizeList.get(0);
        }
        List<AwardRecord> awardRecordList = awardRecordService.queryAwardRecordPage(prizeFontDTO);
        Map result = new HashMap<>();
        result.put("prize",prize);
        result.put("awardRecordList",awardRecordList);
        return AjaxResult.setSuccessData(result);
    }


}
